﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.BarterSystem.Barterables.FiefBarterable
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using System.Collections.Generic;
using TaleWorlds.CampaignSystem.Actions;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.Core;
using TaleWorlds.Localization;
using TaleWorlds.SaveSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem.BarterSystem.Barterables
{
  public class FiefBarterable : Barterable
  {
    [SaveableField(100)]
    private readonly Settlement _settlement;
    [SaveableField(101)]
    private readonly Hero _heroOfferedTo;

    public override string StringID => "fief_barterable";

    public Settlement TargetSettlement => this._settlement;

    public override TextObject Name => this._settlement.Name;

    public FiefBarterable(Settlement settlement, Hero owner, Hero heroOfferedTo)
      : base(owner, (PartyBase) null)
    {
      this._settlement = settlement;
      this._heroOfferedTo = heroOfferedTo;
    }

    public override int GetUnitValueForFaction(IFaction faction)
    {
      float num = 1f;
      if (faction == this._heroOfferedTo.Clan)
        num = 1f;
      else if (faction == this.OriginalOwner.Clan)
        num = -1f;
      else if (faction.MapFaction == this._heroOfferedTo.MapFaction)
        num = 1f;
      else if (faction.MapFaction == this.OriginalOwner.MapFaction)
        num = -1f;
      float settlementValueForFaction = Campaign.Current.Models.SettlementValueModel.CalculateSettlementValueForFaction(this._settlement, faction);
      return (int) ((double) num * (double) settlementValueForFaction);
    }

    public override ImageIdentifier GetVisualIdentifier() => (ImageIdentifier) null;

    public override string GetEncyclopediaLink() => this.TargetSettlement.EncyclopediaLink;

    public override void Apply()
    {
      ChangeOwnerOfSettlementAction.ApplyByBarter(this._heroOfferedTo, this._settlement);
    }

    internal static void AutoGeneratedStaticCollectObjectsFiefBarterable(
      object o,
      List<object> collectedObjects)
    {
      ((Barterable) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
      base.AutoGeneratedInstanceCollectObjects(collectedObjects);
      collectedObjects.Add((object) this._settlement);
      collectedObjects.Add((object) this._heroOfferedTo);
    }

    internal static object AutoGeneratedGetMemberValue_settlement(object o)
    {
      return (object) ((FiefBarterable) o)._settlement;
    }

    internal static object AutoGeneratedGetMemberValue_heroOfferedTo(object o)
    {
      return (object) ((FiefBarterable) o)._heroOfferedTo;
    }
  }
}
